#define _CRT_SECURE_NO_WARNINGS 1
#include <iostream>
#include <cmath>
using namespace std;
bool prime(long long x)
{
    cerr << "x=" << x << endl;
    if (x < 2) return false;
    for (int i = 2;i <= sqrt(x);i++)
    {
        if (x % i == 0) return false;
    }
    return true;
}
int main()
{
    int T = 0;
    cin >> T;
    while (T--)
    {
        long long a = 0, b = 0;
        cin >> a >> b;
        cerr << "a=" << a << ",b=" << b << endl;
        bool f = false;
        if (a == 1) f = prime(b);
        if (b == 1) f = prime(a);
        if (a == 0 || b == 0) f = false;
        if (f) cout << "YES" << endl;
        else cout << "NO" << endl;
    }
    return 0;
}